/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

/**
 *
 * @author user
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import controlador.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;


public class PanelProfesor extends javax.swing.JFrame{

    /**
     * Creates new form PanelProfesor
     */
    
    String codProfesor;
    
    public PanelProfesor(String codProfe) {
        codProfesor = codProfe;
        initComponents();
        this.setLocationRelativeTo(null);
        this.setResizable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPaneProd = new javax.swing.JTabbedPane();
        jPanelProd = new javax.swing.JPanel();
        jComboBoxProd = new javax.swing.JComboBox();
        jPanelNota = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelEst = new javax.swing.JLabel();
        jTextFieldEst = new javax.swing.JTextField();
        jLabelAsig = new javax.swing.JLabel();
        jTextFieldAsig = new javax.swing.JTextField();
        jLabelNota = new javax.swing.JLabel();
        jTextFieldNota = new javax.swing.JTextField();
        jButtonRegistrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Profesor");

        jPanelProd.setOpaque(false);

        jComboBoxProd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "Formacion Academica", "Tesis", "Articulo de Memoria", "Articulo de Revista", "Libro", "Capitulo de Libro" }));
        jComboBoxProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxProdActionPerformed(evt);
            }
        });
        jPanelProd.add(jComboBoxProd);

        jTabbedPaneProd.addTab("Registrar Produccion", jPanelProd);

        jPanelNota.setOpaque(false);

        jLabel1.setText("REGISTRO DE NOTAS FINALES");

        jLabel2.setText("UNIVERSIDAD DEL VALLE");

        jLabelEst.setText("Codigo Estudiante");

        jLabelAsig.setText("Codigo Asignatura");

        jLabelNota.setText("Nota Final");

        jButtonRegistrar.setText("Registrar Nota");
        jButtonRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegistrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelNotaLayout = new javax.swing.GroupLayout(jPanelNota);
        jPanelNota.setLayout(jPanelNotaLayout);
        jPanelNotaLayout.setHorizontalGroup(
            jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNotaLayout.createSequentialGroup()
                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelNotaLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelAsig)
                            .addGroup(jPanelNotaLayout.createSequentialGroup()
                                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelEst)
                                    .addComponent(jLabelNota))
                                .addGap(43, 43, 43)
                                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldAsig, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                                    .addComponent(jTextFieldEst)
                                    .addComponent(jTextFieldNota, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanelNotaLayout.createSequentialGroup()
                        .addGap(84, 84, 84)
                        .addComponent(jButtonRegistrar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelNotaLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelNotaLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(56, 56, 56))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelNotaLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(70, 70, 70))))
        );
        jPanelNotaLayout.setVerticalGroup(
            jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNotaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEst)
                    .addComponent(jTextFieldEst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelAsig)
                    .addComponent(jTextFieldAsig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNota)
                    .addComponent(jTextFieldNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButtonRegistrar)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPaneProd.addTab("Registrar Notas", jPanelNota);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPaneProd)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPaneProd)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxProdActionPerformed
        // TODO add your handling code here:

        int sel = jComboBoxProd.getSelectedIndex();
        System.out.println("se selecciono "+sel);
        Component[] c = jPanelProd.getComponents();
        if(c.length!=1){
            int i=1;
            while(i<c.length){
                jPanelProd.remove(c[i]);
                i++;
            }
        }
        switch(sel){
            case 1: registrarFormacion(); break;
            case 2: registrarTesis(); break;
            case 3: registrarArtMemoria(); break;
            case 4: registrarArticulo((String)jComboBoxProd.getSelectedItem()); break;
            case 5: registrarArticulo((String)jComboBoxProd.getSelectedItem()); break;
            case 6: registrarArticulo((String)jComboBoxProd.getSelectedItem()); break;
            default: System.out.println("ERROR");
        }
    }//GEN-LAST:event_jComboBoxProdActionPerformed

    private void jButtonRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegistrarActionPerformed
        // TODO add your handling code here:
        System.out.println("se va a registrar la nota");
        String est = jTextFieldEst.getText();
        String asignatura = jTextFieldAsig.getText();
        double nota = Double.parseDouble(jTextFieldNota.getText());
        controladorProfesor cp = new controladorProfesor();
        cp.registrarCalificacion(est, asignatura, nota);
        jTextFieldEst.setText("");
        jTextFieldAsig.setText("");
        jTextFieldNota.setText("");
    }//GEN-LAST:event_jButtonRegistrarActionPerformed

    private void registrarFormacion(){

        this.setSize(500, 350);
        final JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(6,2));
        final JButton BRegistrarFormacion = new JButton("Registrar");
        JLabel labelTitulo = new JLabel("TITULO ACADEMICO");
        JLabel labelUniversidad = new JLabel("UNIVERSIDAD");
        JLabel labelNivel = new JLabel("NIVEL");
        JLabel labelAno = new JLabel("AÑO OBTENCION");
        JLabel labelPais = new JLabel("PAIS");
        JLabel labelTesis = new JLabel("TITULO DE TESIS");

        final JTextField campoTitulo = new JTextField(20);
        final JTextField campoUniversidad = new JTextField(20);
        final JTextField campoNivel = new JTextField(20);
        final JTextField campoAno = new JTextField(20);
        final JTextField campoPais = new JTextField(20);
        final JTextField campoTesis = new JTextField(20);

        panel.setVisible(true);
        panel.add(labelTitulo);
        panel.add(campoTitulo);
        panel.add(labelUniversidad);
        panel.add(campoUniversidad);
        panel.add(labelNivel);
        panel.add(campoNivel);
        panel.add(labelAno);
        panel.add(campoAno);
        panel.add(labelPais);
        panel.add(campoPais);
        panel.add(labelTesis);
        panel.add(campoTesis);

        jPanelProd.add(panel);
        jPanelProd.add(BRegistrarFormacion);
        BRegistrarFormacion.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String titulo = campoTitulo.getText();
                String universidad = campoUniversidad.getText();
                String nivel = campoNivel.getText();
                int ano = Integer.parseInt(campoAno.getText());

                Calendar cal = Calendar.getInstance();
                cal.set(ano,01,01);
                Date f = cal.getTime();

                String pais = campoPais.getText();
                String tesis = campoTesis.getText();

                ControladorFormacionAcademica cp = new ControladorFormacionAcademica();
                String msj = cp.insertarFormacion(codProfesor,pais, tesis, titulo, nivel, universidad, f);
                panel.removeAll();
                BRegistrarFormacion.setVisible(false);
                jPanelProd.remove(BRegistrarFormacion);
                jPanelProd.remove(panel);
                jPanelProd.add(new JLabel(msj));
            }
        });
    }

    private void registrarTesis(){

        this.setSize(550, 350);
        final JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(5,2));
        final JButton BRegistrarFormacion = new JButton("Registrar");
        final JComboBox nivelTesis= new JComboBox();
        nivelTesis.addItem("Maestria");
        nivelTesis.addItem("Doctorado");
        JLabel labelEstu = new JLabel("Codigo de estudiante");
        JLabel labelTitulo = new JLabel("Título de tesis");
        JLabel labelNivel = new JLabel("Nivel de tesis");
        JLabel labelFechaIni = new JLabel("Fecha de inicio de tesis");
        JLabel labelEstado = new JLabel("Estado");

        final JTextField campoEstu = new JTextField(20);
        final JTextField campoTitulo = new JTextField(20);
        final JTextField campoFechaIni = new JTextField(20);
        final JTextField campoEstado = new JTextField(20);

        panel.add(labelEstu);
        panel.add(campoEstu);
        panel.add(labelTitulo);
        panel.add(campoTitulo);
        panel.add(labelNivel);
        panel.add(nivelTesis);
        panel.add(labelFechaIni);
        panel.add(campoFechaIni);
        panel.add(labelEstado);
        panel.add(campoEstado);

        jPanelProd.add(panel);
        jPanelProd.add(BRegistrarFormacion);
        BRegistrarFormacion.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String cod_est = campoEstu.getText();
                String titulo = campoTitulo.getText();
                String nivel = (String) nivelTesis.getSelectedItem();
                String fechaIni = campoFechaIni.getText();
                String estado = campoEstado.getText();
                
                SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
                try {
                    Date fecha = f.parse(fechaIni);
                    ControladorTesis ct = new ControladorTesis();
                    String msj = ct.insertarTesis(cod_est, nivel, titulo, fecha, codProfesor);
                    panel.removeAll();
                    BRegistrarFormacion.setVisible(false);
                    jPanelProd.remove(BRegistrarFormacion);
                    jPanelProd.remove(panel);
                    jPanelProd.add(new JLabel(msj));
                }
                catch (ParseException ex){}
                
            }
        });
    }
    
private void registrarArtMemoria(){
        
        this.setSize(400,600);
        this.setResizable(true);
        final JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(15,1));
        final JButton BRegistrarFormacion = new JButton("Registrar");
        
        JLabel labelNombre = new JLabel("Nombre de Articulo");
        JLabel labelRevista = new JLabel("Nombre de Revista");
        JLabel labelGrupo = new JLabel("Grupo al que pertenece");
        JLabel labelFecha = new JLabel("Fecha de Publicacion");
        JLabel labelDia = new JLabel("dia");
        JLabel labelMes = new JLabel("mes");
        JLabel labelAno = new JLabel("ano");
        JLabel labelDiaE = new JLabel("dia");
        JLabel labelMesE = new JLabel("mes");
        JLabel labelAnoE = new JLabel("ano");
        JLabel labelEvento = new JLabel("Nombre de Evento");
        JLabel labelCiudad = new JLabel("Ciudad del Evento");
        JLabel labelFechaEvento = new JLabel("Fecha del Evento");
        
        final JTextField campoNombre = new JTextField(10);
        final JTextField campoRevista = new JTextField(10);
        final JTextField campoGrupo = new JTextField(10);
        final JTextField campoDia = new JTextField(2);
        final JTextField campoMes = new JTextField(2);
        final JTextField campoAno = new JTextField(4);
        final JTextField campoEvento = new JTextField();
        final JTextField campoCiudad = new JTextField();
        final JTextField campoDiaE = new JTextField(2);
        final JTextField campoMesE = new JTextField(2);
        final JTextField campoAnoE = new JTextField(4);
        
        panel.add(labelNombre);
        panel.add(campoNombre);
        panel.add(labelRevista);
        panel.add(campoRevista);
        panel.add(labelGrupo);
        panel.add(campoGrupo);
        panel.add(labelFecha);
        
        JPanel pFecha = new JPanel();
        pFecha.setLayout(new GridLayout(1,6));
        pFecha.add(labelDia);
        pFecha.add(campoDia);
        pFecha.add(labelMes);
        pFecha.add(campoMes);
        pFecha.add(labelAno);
        pFecha.add(campoAno);
        panel.add(pFecha);
        
        panel.add(labelEvento);
        panel.add(campoEvento);
        panel.add(labelCiudad);
        panel.add(campoCiudad);
        panel.add(labelFechaEvento);
        
        JPanel pFechaE = new JPanel();
        pFechaE.setLayout(new GridLayout(1,6));
        pFechaE.add(labelDiaE);
        pFechaE.add(campoDiaE);
        pFechaE.add(labelMesE);
        pFechaE.add(campoMesE);
        pFechaE.add(labelAnoE);
        pFechaE.add(campoAnoE);
        panel.add(pFechaE);
        
        jPanelProd.add(panel);
        jPanelProd.add(BRegistrarFormacion);
        BRegistrarFormacion.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String nombreArt = campoNombre.getText();
                String nombreRevista = campoRevista.getText();
                String grupo = campoGrupo.getText();
                String evento = campoEvento.getText();
                String ciudad = campoCiudad.getText();
                String ano = campoAno.getText();
                String mes = campoMes.getText();
                String dia = campoDia.getText();
                
                SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
                Date fechaPub;
                try{
                    fechaPub = f.parse(dia+"/"+mes+"/"+ano);
                    System.out.println("fecha pub "+fechaPub);
                    ano = campoAnoE.getText();
                    mes = campoMesE.getText();
                    dia = campoDiaE.getText();
                    Date fechaEvento = f.parse(dia+"/"+mes+"/"+ano);
                    System.out.println("fecha EVe "+fechaEvento);
                    
                    ControladorArticuloMemo ca = new ControladorArticuloMemo();
                    String msj = ca.insertarArticuloMemo(evento, ciudad, fechaEvento, nombreArt,
                            "Articulo de Memoria", nombreRevista, grupo, fechaPub, codProfesor);
                    
                    panel.removeAll();
                    BRegistrarFormacion.setVisible(false);
                    jPanelProd.remove(BRegistrarFormacion);
                    jPanelProd.remove(panel);
                    jPanelProd.add(new JLabel(msj));
                }
                catch (ParseException ex) {
                    Logger.getLogger(PanelProfesor.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
    }
    
    private void registrarArticulo(String t){
        
        this.setSize(400,400);
        this.setResizable(true);
        final String tipo = t;
        final JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(8,1));
        final JButton BRegistrarFormacion = new JButton("Registrar");
        
        JLabel labelNombre = new JLabel("Nombre de " + tipo);
        JLabel labelRevista = new JLabel("Nombre de Revista o Libro");
        JLabel labelGrupo = new JLabel("Grupo al que pertenece");
        JLabel labelFecha = new JLabel("Fecha de Publicacion");
        JLabel labelDia = new JLabel("dia");
        JLabel labelMes = new JLabel("mes");
        JLabel labelAno = new JLabel("ano");
        
        final JTextField campoNombre = new JTextField(10);
        final JTextField campoRevista = new JTextField(10);
        final JTextField campoGrupo = new JTextField(10);
        final JTextField campoDia = new JTextField(2);
        final JTextField campoMes = new JTextField(2);
        final JTextField campoAno = new JTextField(4);
        
        panel.add(labelNombre);
        panel.add(campoNombre);
        panel.add(labelRevista);
        panel.add(campoRevista);
        panel.add(labelGrupo);
        panel.add(campoGrupo);
        panel.add(labelFecha);
        JPanel pFecha = new JPanel();
        pFecha.setLayout(new GridLayout(1,6));
        pFecha.add(labelDia);
        pFecha.add(campoDia);
        pFecha.add(labelMes);
        pFecha.add(campoMes);
        pFecha.add(labelAno);
        pFecha.add(campoAno);
        panel.add(pFecha);
        
        jPanelProd.add(panel);
        jPanelProd.add(BRegistrarFormacion);
        BRegistrarFormacion.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String nombreArt = campoNombre.getText();
                String nombreRevista = campoRevista.getText();
                String grupo = campoGrupo.getText();
                String ano = campoAno.getText();
                String mes = campoMes.getText();
                String dia = campoDia.getText();
                
                SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
                Date fecha;
                try {
                    fecha = f.parse(dia+"/"+mes+"/"+ano);
                    ControladorArticulo ca = new ControladorArticulo();
                    String msj = ca.insertarArticulo(nombreArt, tipo, nombreRevista, grupo, fecha, codProfesor);
                    panel.removeAll();BRegistrarFormacion.setVisible(false);
                    jPanelProd.remove(BRegistrarFormacion);
                    jPanelProd.remove(panel);
                    jPanelProd.add(new JLabel(msj));
                }
                catch (ParseException ex) {
                    Logger.getLogger(PanelProfesor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    /**
     * @param args the command line arguments
     */
    
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelProfesor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelProfesor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelProfesor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelProfesor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PanelProfesor(null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonRegistrar;
    private javax.swing.JComboBox jComboBoxProd;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelAsig;
    private javax.swing.JLabel jLabelEst;
    private javax.swing.JLabel jLabelNota;
    private javax.swing.JPanel jPanelNota;
    private javax.swing.JPanel jPanelProd;
    private javax.swing.JTabbedPane jTabbedPaneProd;
    private javax.swing.JTextField jTextFieldAsig;
    private javax.swing.JTextField jTextFieldEst;
    private javax.swing.JTextField jTextFieldNota;
    // End of variables declaration//GEN-END:variables
}
